package com.lakeworks.web.controller.core;

import com.lakeworks.common.annotation.Log;
import com.lakeworks.common.core.controller.BaseController;
import com.lakeworks.common.core.domain.AjaxResult;
import com.lakeworks.common.core.page.TableDataInfo;
import com.lakeworks.common.enums.BusinessType;
import com.lakeworks.domain.OprRewash;
import com.lakeworks.service.IOprRewashService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 返洗记录Controller
 *
 * @author lake
 * @date 2023-02-08
 */
@Controller
@RequestMapping("/system/rewash")
public class OprRewashController extends BaseController {
    private String prefix = "system/rewash";

    @Autowired
    private IOprRewashService oprRewashService;


    @GetMapping()
    public String rewash() {
        return prefix + "/rewash";
    }

    /**
     * 查询返洗记录列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OprRewash oprRewash) {
        startPage();
        List<OprRewash> list = oprRewashService.selectOprRewashList(oprRewash);
        return getDataTable(list);
    }

//    /**
//     * 导出返洗记录列表
//     */
//    @Log(title = "返洗记录", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ResponseBody
//    public AjaxResult export(OprRewash oprRewash)
//    {
//        List<OprRewash> list = oprRewashService.selectOprRewashList(oprRewash);
//        ExcelUtil<OprRewash> util = new ExcelUtil<OprRewash>(OprRewash.class);
//        return util.exportExcel(list, "返洗记录数据");
//    }

    /**
     * 新增返洗记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存返洗记录
     */
    @Log(title = "返洗记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OprRewash oprRewash) {
        return toAjax(oprRewashService.insertOprRewash(oprRewash));
    }

    /**
     * 修改返洗记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        OprRewash oprRewash = oprRewashService.selectOprRewashById(id);
        mmap.put("oprRewash", oprRewash);
        return prefix + "/edit";
    }

    /**
     * 修改保存返洗记录
     */
    @Log(title = "返洗记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OprRewash oprRewash) {
        return toAjax(oprRewashService.updateOprRewash(oprRewash));
    }

    /**
     * 删除返洗记录
     */
    @Log(title = "返洗记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(oprRewashService.deleteOprRewashByIds(ids));
    }
}
